package com.apexsoft.monitor.utils;

import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.File;

/**
 * Created by lgm on 2017/2/17.
 */
public class ConfigFile {

	private static final Logger log = LogManager.getRootLogger();

    public static String getFilePath(String fileName) {
        if (StringUtils.isBlank(fileName)) {
            return null;
        }

        String fileNameContainsPath = Thread.currentThread().getContextClassLoader().getResource(fileName).getPath();
        if (new File(System.getProperty("user.dir") + "/config/" + fileName).exists()) {
            fileNameContainsPath = System.getProperty("user.dir") + "/config/" + fileName;
            log.info("load " + fileName + ":" + fileNameContainsPath);
        } else {
            log.info("load default " + fileName + ":" + fileNameContainsPath);
        }

        return fileNameContainsPath;
    }
}
